package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.core.annotation.Order;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 山顶洞人郑某
 * @className OrderMapper.java
 * @date 2024 02 12
 */
@Mapper
public interface OrderMapper {
    void insert(Orders orders);

    @Select("select * from sky_take_out.orders where number = #{outTradeNo} ")
    Orders getByNumber(String outTradeNo);
    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    Page<Orders> page(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select * from sky_take_out.orders where id = #{id}")
    Orders getById(Long id);
    /**
     * 根据状态统计订单数量
     * @param status
     */
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);
    /*
    订单状态和下单时间查询订单
     */
    @Select("select * from orders where status=#{status} and order_time = #{orderTime}")
    List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime orderTime);

    Double sumByMap(Map<String, Object> map);

    /**
     * 根据条件查询订单数
     * @param map
     * @return
     */
    Integer countBymap(HashMap<String, Object> map);

    /**
     * 统计指定时间区间内的销量排名
     * @param begin
     * @param end
     * @return
     */
    List<GoodsSalesDTO> getSalesTop10(LocalDateTime begin,LocalDateTime end);

    /**
     * 根据订单状态获取订单数量
     * @param status
     * @return
     */
    Integer getOrderCountByStatus(Integer status);

    /**
     * 根据日期其获取营业额
     * @param
     * @return
     */
    @Select("select sum(amount) from orders where order_time <= #{time}")
    Double getAmount(LocalDateTime time);

    Integer countByMap(Map map);
}
